package com.yidu.BusinessData.controller;

import com.yidu.BusinessData.entity.Exchange;
import com.yidu.BusinessData.service.ExchangeServce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
public class ExchangeController {


    @Autowired
    ExchangeServce exchangeServce;

    /**
     * 条件查询加分页
     * @param exchange 模糊查询
     * @param page 起始页
     * @param limit 页数
     * @return 查询方法
     */
    @RequestMapping("selectExchange")
    @ResponseBody
    public Map selectExchange(Exchange exchange,int page,int limit){
        System.out.println("这是分页条件查询的控制器");
        if (exchange.getExchangeName()==null){
            exchange.setExchangeName("");
        }

        System.out.println(exchange.getExchangeName()+"========================");
        System.out.println(exchange.getExchangeType()+"===========fdfsf efs=============");
        List<Exchange> exchangeList = exchangeServce.selectExchange(exchange,page,limit);
        for (Exchange b :
                exchangeList) {
            System.out.println(b);
        }
        int i = exchangeServce.selectCount();
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",i);
        map.put("data",exchangeList);
        return map;
    }

    /**
     * 插入数据
     * @param exchange 券商
     * @return 增加方法
     */
    @RequestMapping("/insertExchange")
    public String insertExchange(Exchange exchange){
        System.out.println("这是增加数据的控制器");
        int i = exchangeServce.selectExchangeFlag(exchange);
        if(i==1){
            return "no";
        }else {
            exchangeServce.insertExchange(exchange);
            return "ok";
        }
    }

    /**
     * 删除数据
     * @param exchange 券商编号
     * @return 删除方法
     */
    @RequestMapping("/deleteExchange")
    public int deleteExchange(Exchange exchange){
        System.out.println("这是删除数据的控制器");
        int i = exchangeServce.deleteExchange(exchange);
        System.out.println("brokerId"+exchange);
        return i;

    }
    @RequestMapping("updateExchange")
    public  int updateExchange(Exchange exchange){
        int i = exchangeServce.updateExchange(exchange);
        return i;
    }
}
